home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / perl5 / File::Find.z / File::Find
Encoding:
Text File  |  1998-10-30  |  2.7 KB  |  133 lines

  1.  
  2.  
  3.  
  4. FFFFiiiilllleeee::::::::FFFFiiiinnnndddd((((3333))))                                                    FFFFiiiilllleeee::::::::FFFFiiiinnnndddd((((3333))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      find - traverse a file tree
  10.  
  11.      finddepth - traverse a directory structure depth-first
  12.  
  13. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  14.          use File::Find;
  15.          find(\&wanted, '/foo','/bar');
  16.          sub wanted { ... }
  17.  
  18.          use File::Find;
  19.          finddepth(\&wanted, '/foo','/bar');
  20.          sub wanted { ... }
  21.  
  22.  
  23. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  24.      The _w_a_n_t_e_d() function does whatever verifications you want.
  25.      $File::Find::dir contains the current directory name, and $_ the current
  26.      filename within that directory.  $File::Find::name contains
  27.      "$File::Find::dir/$_".  You are _c_h_d_i_r()'d to $File::Find::dir when the
  28.      function is called.  The function may set $File::Find::prune to prune the
  29.      tree.
  30.  
  31.      File::Find assumes that you don't alter the $_ variable.  If you do then
  32.      make sure you return it to its original value before exiting your
  33.      function.
  34.  
  35.      This library is primarily for the find2perl tool, which when fed,
  36.  
  37.          find2perl / -name .nfs\* -mtime +7 \
  38.              -exec rm -f {} \; -o -fstype nfs -prune
  39.  
  40.      produces something like:
  41.  
  42.          sub wanted {
  43.              /^\.nfs.*$/ &&
  44.              (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
  45.              int(-M _) > 7 &&
  46.              unlink($_)
  47.              ||
  48.              ($nlink || (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_))) &&
  49.              $dev < 0 &&
  50.              ($File::Find::prune = 1);
  51.          }
  52.  
  53.      Set the variable $File::Find::dont_use_nlink if you're using AFS, since
  54.      AFS cheats.
  55.  
  56.      finddepth is just like find, except that it does a depth-first search.
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. FFFFiiiilllleeee::::::::FFFFiiiinnnndddd((((3333))))                                                    FFFFiiiilllleeee::::::::FFFFiiiinnnndddd((((3333))))
  71.  
  72.  
  73.  
  74.      Here's another interesting wanted function.  It will find all symlinks
  75.      that don't resolve:
  76.  
  77.          sub wanted {
  78.              -l && !-e && print "bogus link: $File::Find::name\n";
  79.          }
  80.  
  81.  
  82. BBBBUUUUGGGGSSSS
  83.      There is no way to make find or finddepth follow symlinks.
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.